<template>
	<view class="pages">
		<view class="boxs">
			<Modkecollege :isShow="false" :list="list" @confirm="confirm" @particulars="particulars"></Modkecollege>
		</view>
	</view>
</template>

<script>
	import Modkecollege from "../../components/Modkecollege/index.vue"
	import {
		getcollectionlist,
		deletecollection
	} from "../../api/api/index.js"
	export default {
		data() {
			return {
				page: 0,
				flag: false,
				limit: 20,
				list: [],
				identity: 0
			}
		},
		methods: {
			public(flag) {
				if (this.flag) {
					return uni.showToast({
						title: "没有更多了",
						icon: "none",
						duration: 1500
					})
				}
				this.page++
				let data = {
					page: this.page,
					limit: this.limit
				}
				uni.showLoading({
					title: "加载中"
				})
				getcollectionlist(data).then(res => {
					uni.hideLoading()
					let lit = res.data.map(v => {
						if (this.identity == 0) {
							v.commodity.prices = v.commodity.price
						} else {
							v.commodity.prices = v.commodity.distributors_price
						}
						return v
					})
					this.list = this.list.concat(lit)
					if (res.data.length < this.limit) {
						this.flag = true
					}
				})
			},
			// 删除商品
			confirm(v) {
				let that = this
				uni.showLoading({
					title: "加载中"
				})
				deletecollection({
					id: v.id
				}).then(res => {
					uni.hideLoading()
					uni.showToast({
						title: res.msg,
						icon: "none",
						duration: 2000
					})
					setTimeout(function() {
						that.page = 0
						that.flag = false
						that.list = []
						that.public()
					}, 2000)
				})
			},
			particulars(v) {
				this.jumpLink({
					link: "/pages/productxq/index",
					query: {
						id: v.commodity.id
					}
				})
			}
		},
		components: {
			Modkecollege
		},
		onShow() {
			this.flag = false
			this.page = 0
			this.list = []
			this.public()
		},
		onLoad() {
			this.identity = uni.getStorageSync("identity")
		},
		onReachBottom() {
			this.public()
		}
	}
</script>

<style scoped lang="scss">
	pages {
		background-color: #FFFFFF;
	}

	.boxs {
		padding: 20rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
	}
</style>
